package com.softwinner.bt.adapter;

import java.util.ArrayList;

import com.softwinner.bt.R;
import com.softwinner.bt.bean.BtContact;
import com.softwinner.bt.bean.PairDevice;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class PairAdapter extends BaseAdapter {
    private ArrayList<PairDevice> devices;
    private Context mContext;
    private LayoutInflater mInflater;
    private int mSelectPosition = -1;

    public PairAdapter(ArrayList<PairDevice> devices, Context context) {
        // TODO Auto-generated constructor stub
        this.devices = devices;
        mContext = context;
        mInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return devices.size();
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return devices.get(position);
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }
    public void setDataChange(ArrayList<PairDevice> devices){
        this.devices=devices;
        this.notifyDataSetChanged();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup arg2) {
        // TODO Auto-generated method stub
        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.list_item, null);
            viewHolder=new ViewHolder();
            viewHolder.name = (TextView) convertView.findViewById(R.id.list_item_label);
            ((ImageView)convertView.findViewById(R.id.list_item_img)).setImageResource(R.drawable.ic_device_thumb);
            convertView.findViewById(R.id.list_item_sublabel).setVisibility(View.GONE);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        if(position == mSelectPosition){
        	convertView.setBackgroundResource(R.drawable.list_item_bg);
        }else{
        	convertView.setBackgroundColor(Color.TRANSPARENT);
        }
        viewHolder.name.setText(devices.get(position).getName());
        return convertView;
    }
    
    public void setSelected(int p){
    	mSelectPosition = p;
    }

    class ViewHolder {
        TextView name;
    }
}
